<script setup lang='ts'>
import CustomNavbar from './componets/CustomNavbar.vue'
import type { BannerItem, CategoryItem } from '@/types/home'
import { ref } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import { getHomeBannerAPI, getHomeCategoryMutliAPI, getUserListRangesAPI } from '@/services/home'
import CategoryPanel from '@/pages/index/componets/CategoryPanel.vue'
import HealthNewsPanel from './componets/HealthNewsPanel.vue'
import type { HealthNews } from '@/types/healthnews'
import { getLittleNews } from '@/services/healthNews'
import HotDocters from '@/pages/index/componets/HotDocters.vue'
import type { User } from '@/types/home'
import PageSkeleton from '@/pages/index/componets/PageSkeleton.vue'

// 获取轮播图数据
const bannerList = ref<BannerItem[]>([])
const getHomeBannerData = async () => {
  const res = await getHomeBannerAPI()
  bannerList.value = res.data
}

// 获取前台分类数据
const categoryList = ref<CategoryItem[]>([])
const getHomeCategoryMutliData = async () => {
  const res = await getHomeCategoryMutliAPI()
  categoryList.value = res.data
}

// 获取健康咨询数据
// const healthlist = ref([])
var messageList = ref<HealthNews[]>([])
// 页面加载时执行的方法
const onPageLoad = async () => {
  const res = await getLittleNews()
  messageList.value = res.data
}

// 获取医生列表信息
const docterList = ref<User[]>([])
const getUserListRanges = async () => {
  const res = await getUserListRangesAPI()
  docterList.value = res.data
}

// 是否加载中标记
const isLoading = ref(false)
onLoad(async () => {
  isLoading.value = true
  await Promise.all([
    getHomeBannerData(),
    getHomeCategoryMutliData(),
    onPageLoad(),
    getUserListRanges(),
  ])
  isLoading.value = false
})
</script>
<template>
  <view class='container'>
    <!-- 自定义导航栏 -->
    <CustomNavbar />
    <scroll-view class='scroll-view'>
      <PageSkeleton v-if='isLoading' />
      <template v-else>
        <!--自定义轮播图-->
        <HosSwiper :list='bannerList' />
        <!--分类面板-->
        <CategoryPanel :list='categoryList' />
        <!--健康资讯-->
        <HealthNewsPanel style='margin-top: 20rpx' :list='messageList' />
        <!--热门医生-->
        <HotDocters style='margin-top: 20rpx' :list='docterList' />
      </template>
    </scroll-view>
  </view>
</template>

<style scoped>
.container {
  background-color: #fbf7f7f2;
  height: 100%;
}

page {
  background-color: #f7f8fa;

}

.scroll-view {
  flex: 1;
}
</style>
